﻿using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Text;
using System.IO;  namespace MalayalamSpellCheck { 	/// <summary> 	/// Summary description for Form1. 	/// </summary> 	public class MalayalamSpellChecker : System.Windows.Forms.Form 	{ 		private NetSpell.SpellChecker.Spelling spelling; 		private NetSpell.SpellChecker.Dictionary.WordDictionary wordDictionary; 		internal System.Windows.Forms.Button spellButton;
        internal System.Windows.Forms.RichTextBox demoRichText;
        private MenuStrip menuStrip1;
        private ToolStripMenuItem fileToolStripMenuItem;
        private ToolStripMenuItem openToolStripMenuItem; 		private System.ComponentModel.IContainer components;  		public MalayalamSpellChecker() 		{ 			// 			// Required for Windows Form Designer support 			// 			InitializeComponent();  			// 			// TODO: Add any constructor code after InitializeComponent call 			// 		}  		/// <summary> 		/// Clean up any resources being used. 		/// </summary> 		protected override void Dispose( bool disposing ) 		{ 			if( disposing ) 			{ 				if (components != null)  				{ 					components.Dispose(); 				} 			} 			base.Dispose( disposing ); 		}  		#region Windows Form Designer generated code 		/// <summary> 		/// Required method for Designer support - do not modify 		/// the contents of this method with the code editor. 		/// </summary> 		private void InitializeComponent() 		{
            this.components = new System.ComponentModel.Container();
            System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
            this.spellButton = new System.Windows.Forms.Button();
            this.demoRichText = new System.Windows.Forms.RichTextBox();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.spelling = new NetSpell.SpellChecker.Spelling(this.components);
            this.wordDictionary = new NetSpell.SpellChecker.Dictionary.WordDictionary(this.components);
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // spellButton
            // 
            this.spellButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.spellButton.Location = new System.Drawing.Point(448, 447);
            this.spellButton.Name = "spellButton";
            this.spellButton.Size = new System.Drawing.Size(80, 23);
            this.spellButton.TabIndex = 3;
            this.spellButton.Text = "Spell Check";
            this.spellButton.Click += new System.EventHandler(this.spellButton_Click);
            // 
            // demoRichText
            // 
            this.demoRichText.AcceptsTab = true;
            this.demoRichText.AutoWordSelection = true;
            this.demoRichText.Dock = System.Windows.Forms.DockStyle.Top;
            this.demoRichText.Font = new System.Drawing.Font("AnjaliOldLipi", 10F);
            this.demoRichText.Location = new System.Drawing.Point(0, 24);
            this.demoRichText.Name = "demoRichText";
            this.demoRichText.ShowSelectionMargin = true;
            this.demoRichText.Size = new System.Drawing.Size(528, 417);
            this.demoRichText.TabIndex = 2;
            this.demoRichText.Text = "മലയാലം";
            this.demoRichText.TextChanged += new System.EventHandler(this.demoRichText_TextChanged);
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(528, 24);
            this.menuStrip1.TabIndex = 4;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // fileToolStripMenuItem
            // 
            this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.openToolStripMenuItem});
            this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
            this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);
            this.fileToolStripMenuItem.Text = "File";
            // 
            // openToolStripMenuItem
            // 
            this.openToolStripMenuItem.Name = "openToolStripMenuItem";
            this.openToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.openToolStripMenuItem.Text = "Open...";
            this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
            // 
            // spelling
            // 
            this.spelling.Dictionary = this.wordDictionary;
            this.spelling.SuggestionMode = NetSpell.SpellChecker.Spelling.SuggestionEnum.NearMiss;
            // 
            // wordDictionary
            // 
            this.wordDictionary.DictionaryFile = "ml-IN.dic";
            this.wordDictionary.DictionaryFolder = ((string)(configurationAppSettings.GetValue("wordDictionary.DictionaryFolder", typeof(string))));
            // 
            // MalayalamSpellChecker
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(528, 476);
            this.Controls.Add(this.spellButton);
            this.Controls.Add(this.demoRichText);
            this.Controls.Add(this.menuStrip1);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "MalayalamSpellChecker";
            this.Text = "Malayalam SpellChecker";
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        } 		#endregion  		/// <summary> 		/// The main entry point for the application. 		/// </summary> 		[STAThread] 		static void Main()  		{ 			Application.Run(new MalayalamSpellChecker()); 		}  		private void spellButton_Click(object sender, System.EventArgs e) 		{ 			this.spelling.ReplacedWord += new NetSpell.SpellChecker.Spelling.ReplacedWordEventHandler(this.spelling_ReplacedWord); 			this.spelling.EndOfText += new NetSpell.SpellChecker.Spelling.EndOfTextEventHandler(this.spelling_EndOfText); 			this.spelling.DeletedWord += new NetSpell.SpellChecker.Spelling.DeletedWordEventHandler(this.spelling_DeletedWord);              this.spelling.Text = this.demoRichText.Text;             this.spelling.SpellCheck(); 		}  		private void spelling_DeletedWord(object sender, NetSpell.SpellChecker.SpellingEventArgs e) 		{ 			int start = this.demoRichText.SelectionStart; 			int length = this.demoRichText.SelectionLength;  			this.demoRichText.Select(e.TextIndex, e.Word.Length); 			this.demoRichText.SelectedText = "";  			if(start > this.demoRichText.Text.Length) 				start = this.demoRichText.Text.Length;  			if((start + length) > this.demoRichText.Text.Length) 				length = 0;  			this.demoRichText.Select(start, length); 		}  		private void spelling_ReplacedWord(object sender, NetSpell.SpellChecker.ReplaceWordEventArgs e) 		{ 			int start = this.demoRichText.SelectionStart; 			int length = this.demoRichText.SelectionLength;  			this.demoRichText.Select(e.TextIndex, e.Word.Length); 			this.demoRichText.SelectedText = e.ReplacementWord;  			if(start > this.demoRichText.Text.Length) 				start = this.demoRichText.Text.Length;  			if((start + length) > this.demoRichText.Text.Length) 				length = 0;  			this.demoRichText.Select(start, length); 		}  		private void spelling_EndOfText(object sender, System.EventArgs e) 		{ 			Console.WriteLine("EndOfText"); 			this.spelling.ReplacedWord -= new NetSpell.SpellChecker.Spelling.ReplacedWordEventHandler(this.spelling_ReplacedWord); 			this.spelling.EndOfText -= new NetSpell.SpellChecker.Spelling.EndOfTextEventHandler(this.spelling_EndOfText); 			this.spelling.DeletedWord -= new NetSpell.SpellChecker.Spelling.DeletedWordEventHandler(this.spelling_DeletedWord); 		}          private void demoRichText_TextChanged(object sender, EventArgs e)         {          }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDlg = new OpenFileDialog();
            DialogResult result = fileDlg.ShowDialog();
            if (result == DialogResult.OK)
            {
                StringBuilder builder = new StringBuilder();
                using(FileStream fs = new FileStream(fileDlg.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (StreamReader streamReader = new StreamReader (fs))
                {
                    

                    string inputLine;
                    while ((inputLine = streamReader.ReadLine()) != null)
                    {
                        builder.AppendLine(inputLine);
                    }
                    
                }

                this.demoRichText.Text = builder.ToString();

            }
        } 	} } 